package com.jet.multichat.server;

import java.io.FileReader;
import java.io.IOException;

import java.util.Scanner;

//TODO:[au] write a contract to the class
public class AuthentificationServer {
	//private String path = new String("/home/student/JVA-004_Java_Basics/labs/ChatExample/src/MultiChat/uins.txt");
	private String path = new String("uins.txt");
	
	public boolean autentificateUser(Message message) throws IOException {
		
		String inMes = message.getText();
		String [] txt = inMes.split(" ");
		String login = txt[0];
		String password = txt[1];
		FileReader file = new FileReader(path);
		Scanner scanner = new Scanner(file);
		boolean exist = false;
		while (scanner.hasNextLine() && !exist){
			String compare = new String(login + " " + password);
			if (scanner.nextLine().equals(compare))
				exist = true;		
		}
		scanner.close();
		file.close();
		return exist;
	
	}
	
}
